import { ScriptModel,IScriptInstance,IBaseScript} from "../../model/scriptList"
import type { ModelCtor,ModelStatic } from "sequelize"

class _ScriptListService {
   async getScriptList() {
     const res = await   ScriptModel.findAll({
            where: {
                is_deleted:false
            }
        })

        return res
    }

    //获取单独剧本
    async getScript(script_id:any){
        const res = await   ScriptModel.findOne({
            where: {
                is_deleted:false,
                id:script_id
            }
        })

        return res
    
    }

    //判断该剧本是否存在
    async scriptExist(scriptName: string) {
        const res = await ScriptModel.findAll({
            where:{
                scriptName
            }
        })
           console.log("判断剧本存在吗",res);

        if(res && res.length > 0){
            return true
         } else {
             return false
         }    
    }

    

    //创建初步剧本
    async createBaseScript(baseScript:any) {
        
        try {
            const createRes = await ScriptModel.create(baseScript);
            console.log("createRes",createRes);
            
            return createRes
        } catch(err) {
            console.log("数据库err", err);
            
        }
    }
}

const ScriptListService = new _ScriptListService()


export {
    ScriptListService
}